package com.blb.netty.encode;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

import java.util.List;

/**
 * 实现字节转long的解码器
 */
public class ByteToLongDecoder extends ByteToMessageDecoder {

    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) throws Exception {
        //判断可读的字节数超过8，就读取8字节
        if(byteBuf.readableBytes() >= 8){
            long l = byteBuf.readLong();
            //存入集合，就完成入站
            list.add(l);
            System.out.println("解码" + l);
        }
    }
}
